﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Config;
using CNVP.Framework.Utils;
using System.IO;

namespace CNVP.JShop.Web.Admin.Template
{
    public partial class TemplateUpload : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Action = Request.Params["Action"];
            string _path = Request.Params["path"];
            if (string.IsNullOrEmpty(_path))
            {
                _path = @"~/Template/Default/";
            }
            switch (Action)
            {
                case "Save":
                    if (Request.Files.Count != 0)
                    {
                        for (int i = 0; i < Request.Files.Count; i++)
                        {
                            HttpPostedFile file = Request.Files[i];
                            string fileExtension = Path.GetExtension(file.FileName).ToLower();
                            if (file.ContentLength > 0 || (!string.IsNullOrEmpty(file.FileName)))
                            {
                                file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(_path + Path.GetFileName(file.FileName.ToLower())));
                            }
                        }
                        Response.Write("<script>window.parent.Finish('恭喜，文件上传操作成功！');</script>");
                    }
                    else
                    {
                        Response.Write("<script>window.parent.Finish('请指定至少一个文件进行上传操作！');</script>");
                    }
                    break;
            }
        }
    }
}